<template>
	<view class="tradingContainer">
		<bnn-loading :loading="isLoading" />
		<view class="Trading-wrap">
			<u-row class="wrap-top" gutter="16" justify="center">
				<u-col span="4">
					<view class="nameClass">{{getdealData.name}}</view>
					<view class="codeClass">{{instrumentId}}</view>
				</u-col>
				<u-col span="4">
					<view class="numClass" style="font-size: 16px;">{{getdealData.last_price}}</view>
					<view class="numClass" style="margin-top: 20rpx;">
						{{getdealData.last_price - getdealData.pre_settlement> 0 ? '+' + (getdealData.last_price - getdealData.pre_settlement).toFixed(2) : (getdealData.last_price - getdealData.pre_settlement).toFixed(2)}}
						{{getdealData.hl}}%
					</view>
				</u-col>

				<u-col span="4">
					<view class="codeClass">卖价:<span style="color:#FA3534;">{{getdealData.ask_price1}}</span></view>
					<view class="codeClass">买价:<span style="color: #FA3534;">{{getdealData.bid_price1}}</span></view>
				</u-col>
			</u-row>
			<u-row class="btuWrap" gutter="16" justify="center">
				<u-col text-align="center" span="4" @click="changeType('1')">
					<view class="btn" :class="[index==='1'?'zhangBtnActive':'zhangBtn']">买涨</view>
				</u-col>
				<u-col text-align="center" span="4" @click="changeType('2')">
					<view class="btn" :class="[index==='2'?'dieBtnActive':'dieBtn']">买跌</view>
				</u-col>
				<u-col text-align="center" span="4" @click="changeType('3')">
					<view class="btn" :class="[index==='3'?'pingBtnActive':'pingBtn']">平仓</view>
				</u-col>
			</u-row>
		</view>
		<view class="pingwrap" v-if="index==3">
			<view class="">
				<view class="">
					<view v-if="allping==0" class="">
						<text>暂无持仓</text>
						<u-icon name="arrow-down" size="28"></u-icon>
					</view>
					<view v-else-if="pingpay==0" class="">
						<text @click="pingshowFn(checked)">平买涨单</text>
						<u-icon name="arrow-down" size="28" @click="pingshowFn(checked)"></u-icon>
					</view>
					<view v-else-if="pingpay==1" class="">
						<text @click="pingshowFn(checked)">平买跌单</text>
						<u-icon name="arrow-down" size="28" @click="pingshowFn(checked)"></u-icon>
					</view>
				</view>
			</view>
			<view class="profitloss" v-if="allping!=0">
				<u-switch v-model="checked" size="30" active-color="#fda600" inactive-color="#d0d1d2"></u-switch>
				<text>止盈止损</text>
			</view>
		</view>
		<view class="computeWrap" v-if="checked&&index==3">
			<view class="computeloss">
				<u-row gutter="10" class="com-t">
					<u-col span="3">若价格达到:</u-col>
					<u-col span="6">
						<u-number-box v-model="valueprofit" @change="profitChange" input-width="225"></u-number-box>
						<!-- <image src="../../../../static/images/wen.png" @click="toCapitalDetail"></image> -->
					</u-col>
					<u-col span="3" class="rowright">触发止盈</u-col>
				</u-row>
				<u-row gutter="10" class="com-t">
					<u-col span="3">若价格达到:</u-col>
					<u-col span="6">
						<u-number-box v-model="valueloss" @change="lossChange" input-width="225"></u-number-box>
					</u-col>
					<u-col span="3" class="rowright">触发止损</u-col>
				</u-row>
				<u-row gutter="10" class="com-t">
					<u-col span="3">委托价：</u-col>
					<u-col span="9">
						<view class="xuanze-wrap">
							<view class="xuanze-btn1" :class="[lossIndex===1?'active':'btn']" @click="lossIndexFn(1)">
								对手价</view>
							<view class="xuanze-btn1" :class="[lossIndex===2?'active':'btn']" @click="lossIndexFn(2)">市价
							</view>
							<u-icon name="question-circle" color="#a8a9ad" size="40" @click="titpingshow=true"></u-icon>
						</view>
					</u-col>
				</u-row>
				<u-row gutter="10" class="com-t">
					<u-col span="3">手数:</u-col>
					<u-col span="9">
						<u-number-box v-model="profitnum" @change="pshouChange" input-width="250"></u-number-box>
					</u-col>
				</u-row>
				<u-row gutter="10" class="com-t1">
					<u-col span="3"></u-col>
					<u-col span="9">最多可平 <text>{{allping}}</text>手</u-col>
				</u-row>
				<u-row gutter="10" class="com-t1">
					<u-col span="3"></u-col>
					<u-col span="9">
						<view class="xuanze-wrap">
							<view class="xuanze-btn1" :class="[fitIndex==0?'active':'btn']" @click="fitIndexfn(0)">全部
							</view>
							<view class="xuanze-btn1" :class="[fitIndex==2?'active':'btn']" @click="fitIndexfn(2)">1/2
							</view>
							<view class="xuanze-btn1" :class="[fitIndex==3?'active':'btn']" @click="fitIndexfn(3)">1/3
							</view>
							<view class="xuanze-btn1" :class="[fitIndex==5?'active':'btn']" @click="fitIndexfn(5)">1/5
							</view>
						</view>
					</u-col>
				</u-row>
				<u-row gutter="10" class="com-t1">
					<u-col span="3">有效期：</u-col>
					<u-col span="9">
						<view class="period_validity" @click="dayshow=true">
							<text>{{validity}} 收盘前 </text>
							<u-icon name="arrow-down"></u-icon>
						</view>
					</u-col>
				</u-row>
				<u-modal v-model="titpingshow" title="委托价说明" :title-style="{fontWeight:'bold'}">
					<view class="slot-content">
						<text class="text_wei">对手价：</text>买入时已卖出价委托，卖出时以买入价委托。 <text
							class="text_right">-----成交概率较高</text> <br><br>
						<text class="text_wei">市价：</text>买入以涨停委托，卖出以跌停价委托。 <text class="text_right">-----成交概率最高</text>
					</view>
				</u-modal>
			</view>
		</view>
		<view class="computeWrap" v-else>
			<view class="compute1">
				<u-row gutter="16" class="com-t">
					<u-col span="4" v-if="index!=3">购买价格:</u-col>
					<u-col span="4" v-if="index==3">平仓价格:</u-col>
					<u-col span="8">
						<view class="com-r">
							<u-number-box v-model="value" @change="valChange" input-width="200"></u-number-box>
							<image src="../../../../static/images/wen.png" @click="toCapitalDetail"></image>
						</view>
					</u-col>
				</u-row>
				<u-row gutter="16" class="com-t">
					<u-col span="4"></u-col>
					<u-col span="8">
						<view class="xuanze-wrap">
							<view class="xuanze-btn" :class="[priceIndex===1?'active':'btn']" @click="priceIndexFn(1)">
								对手价</view>
							<view class="xuanze-btn" :class="[priceIndex===2?'active':'btn']" @click="priceIndexFn(2)">
								最新价</view>
							<view class="xuanze-btn" :class="[priceIndex===3?'active':'btn']" @click="priceIndexFn(3)">
								市价</view>
						</view>
					</u-col>
				</u-row>
				<u-modal v-model="show" title="委托价说明" :title-style="{fontWeight:'bold'}">
					<view class="slot-content">
						<!-- <rich-text :nodes="content"></rich-text> -->
						<text class="text_wei">对手价：</text>买入时已卖出价委托，卖出时以买入价委托。 <text
							class="text_right">-----成交概率较高</text> <br><br>
						<text class="text_wei">最新价：</text>以上一笔成交的价格委托。<br><br>
						<text class="text_right">-----成交概率较低</text> <br><br>
						<text class="text_wei">市价：</text>买入以涨停委托，卖出以跌停价委托。 <text class="text_right">-----成交概率较高</text>
					</view>
				</u-modal>
			</view>
			<view class="compute2">
				<u-row gutter="16" class="com-t">
					<u-col span="4" v-if="index!=3">购买手数:</u-col>
					<u-col span="4" v-if="index==3">平仓手数:</u-col>
					<u-col span="8">
						<view class="com-r">
							<u-number-box v-model="value1" @change="valChange1" input-width="200" :min="1"
								:max="index==3?allping:allhand"></u-number-box>
							<image src="../../../../static/images/shouye.png"></image>
						</view>
					</u-col>
				</u-row>
				<u-row gutter="16" class="com-t">
					<u-col span="4"></u-col>
					<u-col span="8">
						<view class="xuanze-wrap">
							<view class="xuanze-btn" :class="[shouIndex===1?'active':'btn']" @click="shouIndexfn(1)">1/3
							</view>
							<view class="xuanze-btn" :class="[shouIndex===2?'active':'btn']" @click="shouIndexfn(2)">1/2
							</view>
							<view class="xuanze-btn" :class="[shouIndex===3?'active':'btn']" @click="shouIndexfn(3)">全部
							</view>
						</view>
						<view class="tipClass" v-if="index!=3">当前余额最多可买<span style="color: #ff4d59;">{{allhand}}</span>手
						</view>
						<view class="tipClass" v-if="index==3">当前可平<span
								style="color: #ff4d59;">{{pingpay==0?allzping:alltping}}</span>手</view>
					</u-col>
				</u-row>
			</view>
			<!-- 买涨跌止盈止损 -->
			<view class="compute3" v-if="index!=3">
				<view class="Checkstoptit">
					<view class="left">
						<view class="left_top">智能云交易<u-switch @change="checkstopchange" v-model="checkstop" size="40"
								active-color="#ff4d59" inactive-color="#d0d1d2"></u-switch>
						</view>
						<view class="left_bootom">止盈止损说明>></view>

					</view>
					<view class="right">
						止盈止损
					</view>
				</view>
				<view class="" v-if="checkstop">

					<u-row gutter="2" class="com-t">
						<u-col span="2">止盈</u-col>
						<u-col span="5">
							<view class="com-r">
								<u-number-box v-model="stopchecks" @change="stopchecksChange" :disabled="!yingchecks"
									input-width="140" :min="1"></u-number-box>
								<!-- <image src="../../../../static/images/shouye.png"></image> -->
							</view>
						</u-col>
						<u-col span="5">
							<view class="ying_cont">
								<view class="">
									<view class="">盈利：<text class="color_red">{{parseInt(gssp.gparseyin)}}元</text>
									</view>
									<view class="">点位：<text class="color_red">{{parseInt(gssp.yingssp)}}</text></view>
								</view>
								<view class="">
									<u-switch @change="yinchange" v-model="yingchecks" size="25" active-color="#ff4d59"
										inactive-color="#d0d1d2"></u-switch>
								</view>
							</view>
						</u-col>
					</u-row>
					<u-row gutter="2" class="com-t">
						<u-col span="2">止亏</u-col>
						<u-col span="5">
							<view class="com-r">
								<u-number-box v-model="stoplose" @change="stoploseChange" :disabled="!kuichecks"
									input-width="140" :min="1"></u-number-box>
								<!-- <image src="../../../../static/images/shouye.png"></image> -->
							</view>
						</u-col>
						<u-col span="5">
							<view class="ying_cont">
								<view class="">
									<view class="">亏损：<text class="color_green">{{parseInt(gssp.gparsekui)}}元</text>
									</view>
									<view class="">点位：<text class="color_green">{{parseInt(gssp.kuigssp)}}</text></view>
								</view>
								<view class="">
									<u-switch @change="kuichange" v-model="kuichecks" size="25" active-color="#ff4d59"
										inactive-color="#d0d1d2"></u-switch>
								</view>
							</view>
						</u-col>
					</u-row>
					<u-row gutter="10" class="com-t1">
						<u-col span="2">有效期:</u-col>
						<u-col span="9">
							<view class="period_validity" :class="" @click="dayshow=true">
								<text>{{validity}} 收盘前 </text>
								<u-icon name="arrow-down"></u-icon>
							</view>
						</u-col>
					</u-row>
					<view class="bottom_text">触发后默认<text class="color_red">市价（涨跌停价）</text>委托，实际以市场行情价成交</view>
				</view>
			</view>
		</view>

		<view class="foot-view">
			<view class="fitset" v-if="checked&&index==3" @click="setcheckedFn">
				确认设置
			</view>
			<view class="footbtn" v-else>
				<view class="foot-l">
					<view class="msg-c" v-if="index!=3">使用保证金(元)</view>
					<view class="msg-c" v-if="index==3">估计盈亏(元)</view>
					<view class="num-c" v-if="index!=3">{{earnestMoney}}</view>
					<view class="num-c" :class="profitlossprise>=0?'color_red':'color_green'" v-if="index==3">
						{{parseInt(profitlossprise)}}
					</view>
				</view>
				<view v-if="index==1" class="foot-r class1" @click="buyFn">
					<span>确认买涨</span>
				</view>
				<view v-else-if="index==2" class="foot-r class2" @click="buyFn">
					<span>确认买跌</span>
				</view>
				<view v-else-if="index==3&&allping!=0" class="foot-r class3" @click="buyFn">
					<span>确认平仓</span>
				</view>
				<view v-else class="foot-r class4" @click="buyFn">
					<span>暂无持仓</span>
				</view>
			</view>
		</view>

		<u-popup v-model="pingshow" mode="bottom">
			<view class="pingcont">
				<view class="pingtext" @click="pingpayFn(0)">平买涨单</view>
				<view class="pingtext" @click="pingpayFn(1)">平买跌单</view>
				<view class="pingtext pingcancal" @click="pingshow=false">取消</view>
			</view>
		</u-popup>
		<u-popup v-model="dayshow" mode="bottom">
			<view class="pingcont">
				<view class="pingtext" @click="daypanFn(0)">今天</view>
				<view class="pingtext" @click="daypanFn(1)">明天</view>
				<view class="pingtext" @click="daypanFn(2)">一周内</view>
				<view class="pingtext" @click="daypanFn(3)">两周内</view>
				<view class="pingtext pingcancal" @click="dayshow=false">取消</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import BnnLoading from '@/components/bnn-ui/loading/index.vue'
	const dcRichAlert = uni.requireNativePlugin('Trader')
	import {
		formatMoney
	} from '@/utils/index.js'
	// const globalEvent = uni.requireNativePlugin('globalEvent');
	// globalEvent.addEventListener('onErrRtnOrderInsert', function(e) {
	// 	plus.nativeUI.alert('监听条件单'+JSON.stringify(e))
	// })
	export default {
		components: {
			BnnLoading
		},
		data() {
			return {
				gssp: {
					gparseyin: 0,
					gparsekui: 0,
					yingssp: 0,
					kuigssp: 0,
				}, //点位 盈亏
				stopchecks: 15, //止盈比
				stoplose: 10, //止损比
				kuichecks: false,
				yingchecks: false,
				checkstop: false,
				validity: '', //买跌涨盈亏有效期
				lossIndex: 2, //平止盈亏 委托价变量
				fitIndex: 0, //盈亏手数变量
				valueprofit: 0, //触发止盈
				valueloss: 0, //触发止损
				profitnum: 0, //盈亏手数
				checked: false, //平盈亏 切换
				show: false,
				titpingshow: false,
				isLoading: false,
				content: ` <span class="text_wei">对手价：</span>买入时已卖出价委托，卖出时以买入价委托。      -----成交概率较高<br>
				最新价：以上一笔成交的价格委托。<br>
				-----成交概率较低 <br>
				市价：买入以涨停委托，卖出以跌停价委托。 -----成交概率较高`,
				index: 1,
				value: 1,
				value1: 1,
				priceIndex: 3,
				shouIndex: 3,
				id: '',
				getdealData: [], //行情数据
				getTime: null,
				instrumentId: '', //合约id
				OrderRef: 1,
				msgNum: '', //保证金
				profitlossprise: 0, //盈亏价
				plprise: 0,
				allhand: '', //可买手数
				allping: 0, //平手数 做判断用
				allzping: 0, //平涨手数
				alltping: 0, //平跌手数
				pingshow: false, //平涨跌
				pingpay: 0, // 0平买涨  1平买跌
				dayshow: false, // 日期选择
				stopPrice: '', //止损价
				OrderPriceType: '2', //报单价格条件
				ContingentCondition: '2', //止盈 触发条件
				pingweiprise: 0,
				earnestMoney: 0,
				hand: 0
			}
		},
		onLoad(options) {
			// plus.nativeUI.alert(''+JSON.stringify(options))
			this.index = options.index
			this.id = options.id
			this.instrumentId = options.id.split('.')[1]
			this.changeBg()
			try {
				if (options.type == 0) { //涨
					this.pingpay = 0
				} else {
					this.pingpay = 1
				}
				if (options.prise) {
					this.plprise = options.prise
					this.profitlossprise = options.prise
				}
				if (options.loss == 1) {
					this.checked = true
				}
			} catch (e) {
				// error
			}
			let date = new Date()
			let year = date.getFullYear()
			let month = date.getMonth() + 1
			let day = date.getDate()
			let getDate = year + '-' + month + '-' + day
			this.validity = getDate
		},
		onShow() {
			this.dealdataFn()
			setTimeout(() => {
				this.isLoading = false
			}, 1000)
			setTimeout(() => {
				this.isLoading = false
				this.getdata()
			}, 1000)
			setTimeout(() => {
				if (this.index == 3) {
					//this.allhand = parseInt(getApp().globalData.available / this.value) //计算可买手数
					if (this.pingpay == 0) { //涨
						this.allping = this.allzping
					} else {
						this.allping = this.alltping
					}
					this.profitnum = this.allping
				} else {
					//this.allhand = 123 
				}
			}, 1500)
		},
		mounted() {

		},
		onHide() {
			if (this.getTime) {
				clearInterval(this.getTime)
				this.getTime = null
			}
		},
		onUnload() {
			if (this.getTime) {
				clearInterval(this.getTime)
				this.getTime = null
			}
		},
		methods: {
			getdata() {
				//this.getdataRequest()
				
				this.getTime = setInterval(() => {
					setTimeout(this.getdataRequest(), 0)
				}, 1300)
			},
			getdataRequest(){
				let state = true
				uni.request({
					url: 'https://md.sou-liang.com/api/newData',
					data: {
						name: this.id
						//name: 'DCE.a2105'
					},
					success: (res) => {
						this.getdealData = res.data
						if (state) {
							if (this.index == 3) {
								if (this.pingpay == 1) { //平买跌
									this.value = this.getdealData.upper_limit //涨停价
								} else { //平卖涨
									this.value = this.getdealData.lower_limit //跌停价
								}
							} else if (this.index == 2) {
								this.value = this.getdealData.lower_limit //跌停价
							} else {
								this.value = this.getdealData.upper_limit //涨停价
							}
							//this.valueprofit = this.getdealData.last_price
							//this.valueloss = this.getdealData.last_price
							this.msgNum = this.value * this.value1
							state = false
						}
					}
				})
			},
			dealdataFn() { //获取行情
				uni.request({
					url: 'https://md.sou-liang.com/api/newData',
					data: {
						name: this.id
						//name: 'DCE.a2105'
					},
					success: (res) => {
						this.valueprofit = res.data.last_price
						//this.valueprofit = this.getdealData.last_price
						this.valueloss = this.getdealData.last_price
						this.cashDeposit()
						//plus.nativeUI.alert('this.getdealData' + JSON.stringify(this.getdealData))
					}
				})
			},
			cashDeposit() {
				let id = 'MA107'
				this.instrumentCode = this.id.split('.')[1].replace(/[^a-z]+/ig, "");
				//this.instrumentCode = this.instrumentId.replace(/[^a-z]+/ig, "");
				uni.request({
					url: 'https://api.sou-liang.com/api/v1/trade/strategy/cash-deposit',
					data: {
						code: this.instrumentCode
						//code: 'TS'
					},
					success: (res) => {
						let resdata = res.data.data
						let cash_deposit = resdata.cash_deposit / 100
						let ncad = resdata.number * this.valueprofit
						this.earnestMoney = parseInt(cash_deposit * ncad)
						this.allhand = parseInt(balance / this.earnestMoney) //计算可买手数
						//this.allhand = 100 //计算可买手数
						this.value1 = this.allhand
						//plus.nativeUI.alert('allhand'+JSON.stringify(this.allhand))
						//let handStorage = parseInt(balance / this.earnestMoney)
					}
				})
			},
			setcheckedFn() { //设置平仓盈亏
				let dtingen = '6' //最新价大于等于条件价
				let xtingen = '8' //最新价小于等于条件价
				if (this.pingpay == 0) { //平涨单
					if (this.valueprofit <= this.getdealData.last_price) {
						uni.showToast({
							title: '止盈触发价错误，触发价应大于最新价',
							icon: 'none'
						})
						return false
					}
					if (this.valueloss >= this.getdealData.last_price) {
						uni.showToast({
							title: '止损触发价错误，触发价应小于最新价',
							icon: 'none'
						})
						return false
					}
					dtingen = '6'
					xtingen = '8'
				} else {
					if (this.valueprofit >= this.getdealData.last_price) {
						uni.showToast({
							title: '止盈触发价错误，触发价应小于最新价',
							icon: 'none'
						})
						return false
					}
					if (this.valueloss <= this.getdealData.last_price) {
						uni.showToast({
							title: '止损触发价错误，触发价应大于最新价',
							icon: 'none'
						})
						return false
					}
					dtingen = '8'
					xtingen = '6'
				}

				uni.showLoading({
					title: '加载中'
				});
				let {
					accountID,
					brokerID,
					investorID
				} = uni.getStorageSync('TradingAccount');
				let {
					id
				} = uni.getStorageSync('MEMBER_INFO')
				let {
					exchange_id,
					instrument_id
				} = this.getdealData
				let instrumentID = instrument_id.split('.')[1]
				let pay = '0'
				let Flag = '0'
				let Type = '2'
				let StopPri = 0
				// if(this.index==1){//买涨
				// 	pay='0'
				// 	Flag='0'
				// }else if(this.index==2){//买跌
				// 	pay='1'
				// 	Flag='0'
				// }else{
				if (this.pingpay == 0) { //卖涨
					pay = '1'
					Flag = '1'
				} else { //卖跌
					pay = '0'
					Flag = '1'
				}
				if (this.lossIndex == 1) { // 对手价为限价单  
					this.pingweiprise = this.getdealData.ask_price1
					Type = '2'
				} else { //市价 任意价单
					this.pingweiprise = this.getdealData.upper_limit
					Type = '1'
				}
				if (exchange_id == 'SHFE') {
					Type = '2'
				}
				if (exchange_id == 'DCE') {
					Type = '2'
				}
				// }
				let bdata = {
					BrokerID: brokerID, //经纪 
					InvestorID: accountID, //
					InstrumentID: instrumentID, //合约 
					UserID: accountID, //用户
					OrderPriceType: Type, //报单价格条件
					Direction: pay, //买卖方向
					CombOffsetFlag: Flag, //组合开平标志A
					CombHedgeFlag: '1', //组合投机套保标志
					// LimitPrice:this.pingweiprise,//价格this.value
					VolumeTotalOriginal: this.profitnum, //数量this.value1
					TimeCondition: '3', //有效期类型
					StopPrice: this.valueprofit, //止损价
					VolumeCondition: '1', //成交量类型
					ContingentCondition: dtingen, //触发条件    
					ForceCloseReason: '0', //平原因					
					IsAutoSuspend: 0, //自动挂起标志					
					UserForceClose: 0, //用户强评标志
					IsSwapOrder: 0, //互换单标志
					ExchangeID: exchange_id, //交易所代码exchange_id
					AccountID: accountID, //资金账号accountID	
					// :this.validity //时间
				}
				let diedata = {
					BrokerID: brokerID, //经纪 
					InvestorID: accountID, //
					InstrumentID: instrumentID, //合约 
					UserID: accountID, //用户
					OrderPriceType: Type, //报单价格条件
					Direction: pay, //买卖方向
					CombOffsetFlag: Flag, //组合开平标志A
					CombHedgeFlag: '1', //组合投机套保标志
					// LimitPrice:this.pingweiprise,//价格this.value
					VolumeTotalOriginal: this.profitnum, //数量this.value1
					TimeCondition: '3', //有效期类型
					StopPrice: this.valueloss, //止损价
					VolumeCondition: '1', //成交量类型
					ContingentCondition: xtingen, //触发条件
					ForceCloseReason: '0', //平原因					
					IsAutoSuspend: 0, //自动挂起标志					
					UserForceClose: 0, //用户强评标志
					IsSwapOrder: 0, //互换单标志
					ExchangeID: exchange_id, //交易所代码exchange_id
					AccountID: accountID, //资金账号accountID	
					// :this.validity //时间
				}
				if (Type == 2) {
					bdata.LimitPrice = this.pingweiprise
					diedata.LimitPrice = this.pingweiprise
				}

				try {
					let astat = 1
					plus.nativeUI.alert('提交盈条件数据' + JSON.stringify(bdata))
					dcRichAlert.reqOrderInsert(bdata, function(ret) {
						plus.nativeUI.alert('条件单回调' + JSON.stringify(ret))
						if (res.code == 16 && res.code == 42) { //16  data==0
							// uni.hideLoading();						
							uni.showToast({
								title: res.message,
								icon: 'none'
							})
							// uni.setStorageSync('Declaration_key', res.data);						
						} else {
							uni.showToast({
								title: res.message,
								icon: 'none'
							})
							uni.hideLoading();
							// uni.switchTab({
							// 	url: '/pages/tabBar/transaction/index'
							// });
						}
						// ste=1
						// uni.hideLoading(); 	uni.setStorageSync('globalAccount',globalData);
						// plus.nativeUI.alert('进入')
					})
					plus.nativeUI.alert('提交跌条件数据' + JSON.stringify(diedata))
					dcRichAlert.reqOrderInsert(diedata, function(res) {
						// plus.nativeUI.alert('提交报单'+JSON.stringify(res))
						if (res.code == 16 && res.code == 42) { //16  data==0
							uni.showToast({
								title: res.message,
								icon: 'none'
							})
							// uni.setStorageSync('Declaration_key', res.data);						
						} else {
							uni.showToast({
								title: res.message,
								icon: 'none'
							})

						}
						astat = 2
						uni.hideLoading();
					})
					setTimeout(() => {
						uni.hideLoading();
						uni.switchTab({
							url: '/pages/tabBar/transaction/index'
						});
						// if (astat == 1) {}
					}, 2000)
				} catch (e) {
					plus.nativeUI.alert('报错条件单' + JSON.stringify(e))
				}
			},
			pingshowFn(bool) {
				if (bool) {

				} else {
					this.pingshow = true
				}
			},
			profitChange(i) {
				// i
				// this.valueprofit=this.getdealData.last_price
			},
			lossChange(i) {
				// i
			},
			pshouChange(i) {
				// i
			},
			checkstopchange(bool) {
				// bool
			},
			yinchange(bool) {
				if (bool) {
					// this.stoplose=10
					this.gssp.gparseyin = this.value1 * this.value * this.stopchecks / 100
					this.gssp.yingssp = this.value * this.stopchecks / 100 + this.value
					// this.stopPrice=
				} else {
					this.gssp.yingssp = 0
					this.gssp.gparseyin = 0
					// this.stopchecks=0
				}
			},
			kuichange(bool) {
				if (bool) {
					// this.stopchecks=10
					this.gssp.kuigssp = this.value - this.value * this.stoplose / 100
					this.gssp.gparsekui = this.value1 * this.value * this.stoplose / 100
					// this.stopPrice=
				} else {
					this.gssp.kuigssp = 0
					this.gssp.gparsekui = 0
					// this.stopchecks=0
				}
			},
			stoploseChange(data) {
				let {
					value
				} = data
				if (value == 0) {
					this.gssp.kuigssp = 0
				} else {
					this.gssp.kuigssp = this.value - this.value * this.stoplose / 100
					this.gssp.gparsekui = this.value1 * this.value * this.stoplose / 100
				}
				// OrderPriceType
			},
			stopchecksChange(data) {
				let {
					value
				} = data
				if (value == 0) {
					this.gssp.yingssp = 0
				} else {
					this.gssp.gparseyin = this.value1 * this.value * this.stopchecks / 100
					this.gssp.yingssp = this.value * value / 100 + this.value
				}
			},
			daypanFn(index) {
				let date = new Date()
				let year = date.getFullYear()
				let month = date.getMonth() + 1
				let day = date.getDate()
				let daynum = new Date(year, month, 0).getDate()
				if (index == 1) {
					day += 1
					if (day > daynum) {
						month += 1
						day = daynum - day
					}
					if (month > 12) {
						year += 1
					}
				} else if (index == 2) {
					day += 6
					if (day > daynum) {
						month += 1
						day = daynum - day
					}
					if (month > 12) {
						year += 1
					}
				} else if (index == 3) {
					day += 13
					if (day > daynum) {
						month += 1
						day = daynum - day
					}
					if (month > 12) {
						year += 1
					}
				} else {}
				let getDate = year + '-' + month + '-' + day
				this.validity = getDate
				this.dayshow = false
			},
			lossIndexFn(index) {
				this.lossIndex = index
				// if(index==1){
				// 	this.pingweiprise=this.getdealData.ask_price1
				// }else{
				// 	this.pingweiprise=this.getdealData.upper_limit
				// }
			},
			fitIndexfn(index) {
				this.fitIndex = index
				if (index == 0) {
					this.profitnum = this.allping
				} else if (index == 2) {
					this.profitnum = this.allping / 2
				} else if (index == 3) {
					this.profitnum = this.allping / 3
				} else {
					this.profitnum = this.allping / 5
				}
			},
			change(status) {
				// status
			},
			pingpayFn(index) {
				this.pingpay = index
				this.pingshow = false
				if (this.pingpay == 1) { //平买跌
					this.value = this.getdealData.upper_limit //涨停价
					this.allping = this.alltping
				} else { //平卖涨
					this.value = this.getdealData.lower_limit //跌停价
					this.allping = this.allzping
				}
			},
			shouIndexfn(index) {
				this.shouIndex = index
				if (this.index == 3) {
					if (index == 1) {
						this.value1 = parseInt(this.allping / 3)
					} else if (index == 2) {
						this.value1 = parseInt(this.allping / 2)
					} else {
						this.value1 = this.allping
					}
				} else {
					if (index == 1) {
						this.value1 = parseInt(this.allhand / 3)
					} else if (index == 2) {
						this.value1 = parseInt(this.allhand / 2)
					} else {
						this.value1 = this.allhand
					}
				}
			},
			priceIndexFn(index) { //切换买涨跌 平
				this.priceIndex = index
				if (index == 1) {
					if (this.index == 1) {
						this.value = this.getdealData.ask_price1 //卖价
					} else {
						this.value = this.getdealData.bid_price1 //买价
						// this.value=this.getdealData.lower_limit//跌停价
					}
				} else if (index == 2) {
					// this.value=this.getdealData.last_price
					this.value = this.getdealData.bid_price1
				} else {
					if (this.index == 3) {
						if (this.pingpay == 1) { //平买跌
							this.value = this.getdealData.upper_limit //涨停价
						} else { //平卖涨
							this.value = this.getdealData.lower_limit //跌停价
						}
					} else if (this.index == 2) {
						this.value = this.getdealData.lower_limit //跌停价
					} else {
						this.value = this.getdealData.upper_limit //涨停价
					}

				}
			},
			buyFn() { //确认报单
				if (this.index == 3 && this.allping == 0) {
					return false
				}
				uni.showLoading({
					title: '加载中'
				});
				const {
					accountID,
					brokerID,
					investorID
				} = uni.getStorageSync('TradingAccount');
				let {
					id
				} = uni.getStorageSync('MEMBER_INFO')
				let {
					exchange_id,
					instrument_id
				} = this.getdealData
				let instrumentID = instrument_id.split('.')[1]
				// let data={}
				let pay = '0'
				let Flag = '0'
				let gent = '1'
				// let LmPrice=this.getdealData.
				// let data={
				// 	BrokerID:'9999',//经纪 brokerID
				// 	InvestorID:'174204',//accountID
				// 	InstrumentID:'ic2102',//合约 instrumentID
				// 	UserID:'174204',//用户accountID
				// 	OrderPriceType:'2',//报单价格条件
				// 	Direction:'0',//买卖方向
				// 	CombOffsetFlag:'0',//组合开平标志A
				// 	CombHedgeFlag:'1',//组合投机套保标志
				// 	LimitPrice:6309,//价格this.value
				// 	VolumeTotalOriginal:1,//数量this.value1
				// 	TimeCondition:'3',//有效期类型
				// 	VolumeCondition:'1',//成交量类型
				// 	ContingentCondition:'1',//触发条件
				// 	ForceCloseReason:'0',//平原因					
				// 	IsAutoSuspend:0,//自动挂起标志					
				// 	UserForceClose:0,//用户强评标志
				// 	IsSwapOrder:0,//互换单标志
				// 	ExchangeID:'CFFEX',//交易所代码exchange_id
				// 	AccountID:'174204',//资金账号accountID	
				// 	// MinVolume:0,//最小成交量
				// 	// StopPrice:0.0,//止损价
				// 	// RequestID:0,//请求编号
				// 	// OrderRef:'12',//报单
				// 	// GTDDate:'2021',//GTD日期
				// 	// BusinessUnit:'9999cac',//业务单元
				// 	// InvestUnitID:'1',//投资单元
				// 	// CurrencyID:'1',//币种
				// 	// ClientID:'1',//交易
				// 	// IPAddress:'1',//IP地址
				// 	// MacAddress:'1',//Mac地址
				// }
				if (this.index == 1) { //买涨
					pay = '0'
					Flag = '0'
				} else if (this.index == 2) { //买跌
					pay = '1'
					Flag = '0'
				} else {
					if (this.pingpay == 0) { //卖涨
						pay = '1'
						Flag = '1'
					} else { //卖跌
						pay = '0'
						Flag = '1'
					}
				}
				//Flag 1 平 0 开
				//pay  1 卖 0 买
				//买入+开仓= 买涨，卖出+开仓=买跌
				//卖出+平仓=卖涨，买入+平仓=卖跌
				if (this.checkstop) {
					if (this.yingchecks) {
						// this.OrderPriceType='1'
						this.stopPrice = this.gssp.yingssp
						gent = '3'
						// upper_limit
					}
					if (this.kuichecks) {
						// this.OrderPriceType='1'
						this.stopPrice = this.gssp.kuigssp
						gent = '2'
						// lower_limit
					}
				} else {
					gent = '1'
					this.OrderPriceType = '2'
					// this.stopPrice=this.value+this.value*0.1
				}
				let data = {
					BrokerID: brokerID, //经纪 
					InvestorID: accountID, //
					InstrumentID: instrumentID, //合约 
					UserID: accountID, //用户
					OrderPriceType: '2', //报单价格条件
					Direction: pay, //买卖方向
					CombOffsetFlag: Flag, //组合开平标志A
					CombHedgeFlag: '1', //组合投机套保标志
					LimitPrice: this.value, //价格this.value
					VolumeTotalOriginal: 1, //数量this.value1
					TimeCondition: '3', //有效期类型
					// StopPrice:this.stopPrice,//止损价
					VolumeCondition: '1', //成交量类型
					ContingentCondition: gent, //触发条件
					ForceCloseReason: '0', //平原因					
					IsAutoSuspend: 0, //自动挂起标志					
					UserForceClose: 0, //用户强评标志
					IsSwapOrder: 0, //互换单标志
					ExchangeID: exchange_id, //交易所代码exchange_id
					AccountID: accountID, //资金账号accountID	
				}
				// if(this.checkstop){
				// 	data['StopPrice']=this.stopPrice
				// }
				 plus.nativeUI.alert('参数'+JSON.stringify(data),'sadas---'+this.value1)	
				//报单		
				try {
					let ste = 0
					dcRichAlert.reqOrderInsert(data, function(res) {
						// plus.nativeUI.alert('提交报单'+JSON.stringify(res))
						if (res.code == 16 && res.code == 42) { //16  data==0
							uni.showToast({
								title: res.message,
								icon: 'none'
							})
							// uni.setStorageSync('Declaration_key', res.data);						
						} else {
							uni.showToast({
								title: res.message,
								icon: 'none'
							})
						}
						ste = 1
						uni.hideLoading();
					})
					setTimeout(() => {
						if (ste == 0) {
							uni.hideLoading();
							uni.switchTab({
								url: '/pages/tabBar/transaction/index'
							});
						}
					}, 2000)
				} catch (e) {
					plus.nativeUI.alert('cuowu' + JSON.stringify(e))
				}
			},
			valChange(e) {
				this.msgNum = this.value * this.value1
			},
			toCapitalDetail() {
				this.show = true
				// uni.navigateTo({
				// 	url: '../capitalDetail/index?id=1'
				// })
			},
			valChange1(e) {
				if (this.index == 3) {
					this.profitlossprise = this.plprise * this.value1
				} else {
					e = this.hand
					// this.msgNum = this.value * this.value1
				}
			},
			changeType(index) {
				this.index = index
				this.changeBg()
			},
			changeBg() {
				let that = this
				var bgcolor = '#ff4d59'
				if (this.index == 1) {
					bgcolor = '#ff4d59'
					// this.value1
					this.priceIndexFn(this.priceIndex)
					this.shouIndexfn(3)
					this.dealdataFn()
				} else if (this.index == 2) {
					bgcolor = '#3dbf61'
					// this.value1=this.allping
					// this.value1 
					this.shouIndexfn(3)
					this.priceIndexFn(this.priceIndex)
					this.dealdataFn()
				} else {
					this.priceIndexFn(this.priceIndex)
					bgcolor = '#fda600'
					try {
						const reqtion = uni.getStorageSync('reqQryposition')
						// plus.nativeUI.alert('获取手数存储'+JSON.stringify(reqtion))
						if (reqtion) {
							const pingdata = reqtion
							let r = pingdata.filter(function(element, index, self) {
								return element.instrumentID == that.instrumentId;
							});
							// plus.nativeUI.alert('筛选'+JSON.stringify(r))
							let rleng = r.length
							for (let i = 0; i < rleng; i++) {
								if (r[i].posiDirection == 2) { //涨
									this.allzping += r[i].position
								} else { //跌
									this.alltping += r[i].position
								}
							}

							// this.value1=this.allping
							// this.allping=r.position
						} else {
							this.allping = 0
							// this.index=4
						}
					} catch (e) {
						plus.nativeUI.alert('获取手数报错' + JSON.stringify(e))
					}
				}
				uni.setNavigationBarColor({
					frontColor: '#ffffff',
					backgroundColor: bgcolor,
					animation: {
						duration: 400,
						timingFunc: 'easeIn'
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.ying_cont {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.Checkstoptit {
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 15px;

		.left {
			display: flex;
			flex-direction: column;

			.left_top {
				display: flex;
				// justify-content: center;
				align-items: center;
				font-size: 16px;
				font-weight: 800;
			}

			.left_bootom {
				margin-top: 5px;
				font-size: 12px;
			}
		}

		.right {
			background-color: #000;
			color: #fff;
			padding: 5px;
			border-radius: 5px;
		}

	}

	.bottom_text {
		font-size: 12px;
		padding: 10px;

	}

	.color_red {
		color: #ff4d59;
	}

	.color_green {
		color: #3dbf61;
	}

	.period_validity {
		width: 100%;
		border: 1px solid #f1f1f1;
		color: #000;
		font-weight: 800;
		font-size: 15px;
		border-radius: 3px;
		padding: 6px;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.fitset {
		width: 100%;
		height: 100%;
		text-align: center;
		display: flex;
		justify-content: center;
		align-items: center;
		color: #fff;
		font-size: 16px;
		background-color: #fda600;
	}

	.profitloss {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.rowright {
		text-align: right !important;
	}

	.pingcont {
		background-color: #E9E9E9;
	}

	.pingtext {
		width: 100%;
		padding: 15px 0;
		text-align: center;
		border-bottom: 1px solid #E9E9E9;
		background-color: #fff;
		// font-size: 16px;line-height: ;
	}

	.pingcancal {
		margin-top: 15px;
		color: #adaaaa;
	}

	.slot-content {
		font-size: 28rpx;
		color: $u-content-color;
		padding: 20px 15px;

	}

	.text_wei {
		color: #000;
		font-weight: bold;
	}

	.text_right {
		text-align: right;
		float: right;
		color: rgb(41, 121, 255);
	}

	.tradingContainer {
		width: 100%;
		height: 100%;

		.Trading-wrap {
			width: 100%;
			height: 280rpx;
			background-color: $uni-bg-color;

			.u-col {
				margin-top: 20rpx;
			}

			.wrap-top {
				width: 100%;
				padding-left: 20rpx;

				.nameClass {
					font-size: $uni-font-size-lg;
				}

				.codeClass {
					font-size: $uni-font-size-sm;
					color: $uni-text-color-grey;
					margin-top: 10rpx;
				}

				.numClass {
					color: #ff4d59;
					font-size: $uni-font-size-sm;
				}
			}

			.btuWrap {
				width: 100%;
				height: 150rpx;
				line-height: 150rpx;
				text-align: center;
				font-size: $uni-font-size-lg;

				.btn {
					width: 210rpx;
					height: 70rpx;
					text-align: center;
					line-height: 70rpx;
					border-radius: 10rpx;
					margin-left: 10rpx;
				}

				.zhangBtnActive {
					background-color: #ff4d59;
					color: #FFFFFF;
				}

				.zhangBtn {
					border: 1px solid #ff4d59;
					color: #ff4d59;
				}

				.dieBtnActive {
					background-color: #3dbf61;
					color: #FFFFFF;
				}

				.dieBtn {
					border: 1px solid #3dbf61;
					color: #3dbf61;
				}

				.pingBtnActive {
					background-color: #fda600;
					color: #FFFFFF;
				}

				.pingBtn {
					border: 1px solid #fda600;
					color: #fda600;
				}
			}
		}

		.pingwrap {
			width: 100%;
			margin-top: 20rpx;
			background-color: $uni-bg-color;
			padding: 20px 15px;
			display: flex;
			justify-content: space-between;
			align-items: center;
		}

		.computeWrap {
			width: 100%;
			// min-height: 500rpx;
			background-color: $uni-bg-color;
			margin-top: 20rpx;

			// max-height: 600rpx;
			.compute1 {
				width: 100%;
				height: 200rpx;
				border-bottom: 1px solid #F2F2F2;
			}

			.computeloss {
				width: 100%;
			}

			.compute2 {
				width: 100%;
				// height: 200rpx;
			}

			.compute3 {
				width: 100%;
				// height: 200rpx;
				padding: 0 0 100px;
			}

			.com-t1 {
				padding: 10rpx 20rpx;
				color: $uni-text-color-grey;
			}

			.com-t {
				padding: 20rpx;
				color: $uni-text-color-grey;

				.com-r {
					width: 100%;
					display: flex;
					justify-content: center;
					align-items: center;

					image {
						width: 40rpx;
						height: 40rpx;
						margin-left: 40rpx;
					}
				}
			}

			.xuanze-wrap {
				width: 100%;
				display: flex;
				justify-content: center;
				align-items: center;

				.active {
					color: #fda600;
					border: 1px solid #fda600;
					background-color: #fef8ec;
				}

				.btn {
					background-color: #fafafa;
				}

				.xuanze-btn {
					flex: 1;
					width: 150rpx;
					height: 60rpx;
					line-height: 60rpx;
					text-align: center;
					margin-left: 20rpx;
					font-size: $uni-font-size-sm;
					border-radius: 10rpx;
					border: 1px solid #f1f1f1;
				}

				.xuanze-btn1 {
					flex: 1;
					// width: 150rpx;
					height: 60rpx;
					line-height: 60rpx;
					text-align: center;
					margin-right: 10rpx;
					font-size: $uni-font-size-sm;
					border-radius: 10rpx;
					border: 1px solid #f1f1f1;
				}
			}

			.tipClass {
				width: 95%;
				border-radius: 10rpx;
				border: 1px solid #f1f1f1;
				height: 50rpx;
				line-height: 50rpx;
				font-size: $uni-font-size-sm;
				color: $uni-text-color-grey;
				background-color: #fafafa;
				margin: 20rpx;
				padding-left: 20rpx;
			}
		}

		.foot-view {
			width: 100%;
			height: 100rpx;
			position: fixed;
			bottom: 0;

			.footbtn {
				display: flex;
				justify-content: center;
				align-items: center;

				.foot-l {
					flex: 1;
					background-color: #FFFFFF;
					padding: 10rpx;
					height: 100rpx;

					.msg-c {
						font-size: $uni-font-size-sm;
						color: $uni-text-color-grey;
						margin-top: 5rpx;
					}

					.num-c {
						font-size: $uni-font-size-lg;
						color: #ff4d59;
						margin-top: 10rpx;
					}
				}

				.class1 {
					background-color: #ff4d59;
				}

				.class2 {
					background-color: #3dbf61;
				}

				.class3 {
					background-color: #fda600;
				}

				.class4 {
					background-color: #868685;
				}

				.foot-r {
					flex: 1;
					height: 100rpx;
					line-height: 100rpx;
					color: #FFFFFF;
					text-align: center;
				}
			}
		}
	}
</style>
